package com.wz.project.cxtj.cargoSpaceHistory.controller;

import com.wz.common.utils.poi.ExcelUtil;
import com.wz.framework.aspectj.lang.annotation.Log;
import com.wz.framework.aspectj.lang.enums.BusinessType;
import com.wz.framework.web.controller.BaseController;
import com.wz.framework.web.domain.AjaxResult;
import com.wz.framework.web.page.TableDataInfo;
import com.wz.project.cxtj.cargoSpaceHistory.domain.ViewCargospaceHistory;
import com.wz.project.cxtj.cargoSpaceHistory.service.IViewCargospaceHistoryService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 货位履历Controller
 * 
 * @author qxq
 * @date 2021-11-02
 */
@Controller
@RequestMapping("/search/cargoSpaceHistory")
public class ViewCargospaceHistoryController extends BaseController
{
    private String prefix = "cxtj/cargoSpaceHistory";

    @Autowired
    private IViewCargospaceHistoryService viewCargospaceHistoryService;

//    @RequiresPermissions("search:cargoSpaceHistory:view")
    @GetMapping()
    public String cargoSpaceHistory()
    {
        return prefix + "/cargoSpaceHistory";
    }

    /**
     * 查询货位履历列表
     */
//    @RequiresPermissions("search:cargoSpaceHistory:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ViewCargospaceHistory viewCargospaceHistory)
    {
        startPage();
        List<ViewCargospaceHistory> list = viewCargospaceHistoryService.selectViewCargospaceHistoryList(viewCargospaceHistory);
        return getDataTable(list);
    }

    /**
     * 导出货位履历列表
     */
    @RequiresPermissions("search:cargoSpaceHistory:export")
    @Log(title = "货位履历", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ViewCargospaceHistory viewCargospaceHistory)
    {
        List<ViewCargospaceHistory> list = viewCargospaceHistoryService.selectViewCargospaceHistoryList(viewCargospaceHistory);
        ExcelUtil<ViewCargospaceHistory> util = new ExcelUtil<ViewCargospaceHistory>(ViewCargospaceHistory.class);
        return util.exportExcel(list, "cargoSpaceHistory");
    }

    /**
     * 新增货位履历
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存货位履历
     */
    @RequiresPermissions("search:cargoSpaceHistory:add")
    @Log(title = "货位履历", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ViewCargospaceHistory viewCargospaceHistory)
    {
        return toAjax(viewCargospaceHistoryService.insertViewCargospaceHistory(viewCargospaceHistory));
    }

    /**
     * 修改货位履历
     */
    @GetMapping("/edit/{cargoSpaceName}")
    public String edit(@PathVariable("cargoSpaceName") String cargoSpaceName, ModelMap mmap)
    {
        ViewCargospaceHistory viewCargospaceHistory = viewCargospaceHistoryService.selectViewCargospaceHistoryById(cargoSpaceName);
        mmap.put("viewCargospaceHistory", viewCargospaceHistory);
        return prefix + "/edit";
    }

    /**
     * 修改保存货位履历
     */
    @RequiresPermissions("search:cargoSpaceHistory:edit")
    @Log(title = "货位履历", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ViewCargospaceHistory viewCargospaceHistory)
    {
        return toAjax(viewCargospaceHistoryService.updateViewCargospaceHistory(viewCargospaceHistory));
    }

    /**
     * 删除货位履历
     */
    @RequiresPermissions("search:cargoSpaceHistory:remove")
    @Log(title = "货位履历", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(viewCargospaceHistoryService.deleteViewCargospaceHistoryByIds(ids));
    }
}
